//
//  ShowExhibitorNameCell.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/30.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "ShowExhibitorNameCell.h"
#import "XXTool.h"


@interface ShowExhibitorNameCell ()

@property (nonatomic) UILabel *cName;

@property (nonatomic) UILabel *eName;

@end

@implementation ShowExhibitorNameCell
{
    CGFloat topGap;
    CGFloat leftGap;
}

-(UILabel*)cName
{
    if (_cName==nil)
    {
        _cName = [[UILabel alloc] init];
        _cName.font = [XXTool systemFontOfSize:16.5f];
        _cName.numberOfLines = 0;
        [self addSubview:_cName];
    }
    return _cName;
}

-(UILabel*)eName
{
    if (_eName==nil)
    {
        _eName = [[UILabel alloc] init];
        _eName.font = [XXTool systemFontOfSize:16.5f];
        _eName.numberOfLines = 0;
        [self addSubview:_eName];
    }
    return _eName;
}

-(void)initParameter
{
    topGap = 18;
    leftGap = 15;
}

-(void)initUI
{
    [self cName];
    [self eName];
}

-(void)refreshLayout:(CGRect)frame
{
    if ([_cName.text isEqualToString:@""]&&[_eName.text isEqualToString:@""])
    {
        _cName.hidden = YES;
        _eName.hidden = YES;
    }
    //只有中文名
    else if([_eName.text isEqualToString:@""])
    {
        _cName.hidden = NO;
        _eName.hidden = YES;
        
        _cName.frame = CGRectMake(leftGap
                                  , topGap
                                  , [UIScreen mainScreen].bounds.size.width-leftGap*2
                                  , [XXTool getTextHeightByText:_cName.text Font:[XXTool systemFontOfSize:16.5] Width:_cName.frame.size.width]);
        
    }
    //只有英文名
    else if ([_cName.text isEqualToString:@""])
    {
        _cName.hidden = YES;
        _eName.hidden = NO;
        
        _eName.frame = CGRectMake(leftGap
                                  , topGap
                                  , [UIScreen mainScreen].bounds.size.width-leftGap*2
                                  , [XXTool getTextHeightByText:_eName.text Font:[XXTool systemFontOfSize:16.5] Width:_eName.frame.size.width]);
    }
    //都有
    else
    {
        _eName.hidden = NO;
        _cName.hidden = NO;
        
        
        _cName.frame = CGRectMake(leftGap
                                  , topGap
                                  , [UIScreen mainScreen].bounds.size.width-leftGap*2
                                  , [XXTool getTextHeightByText:_cName.text Font:[XXTool systemFontOfSize:16.5] Width:_cName.frame.size.width]);
            
        _eName.frame = CGRectMake(leftGap
                                  , _cName.frame.size.height+_cName.frame.origin.y-2
                                  , _cName.frame.size.width
                                  , [XXTool getTextHeightByText:_eName.text Font:[XXTool systemFontOfSize:16.5] Width:_eName.frame.size.width]);
    }
    
}

-(void)setCellWithData:(RXMLExhibitorInformationModel*)model
{
    _cName.text = model.CompanyName_chn;
    _eName.text = model.CompanyName_eng;
    [self refreshLayout:self.frame];
}
    
+(CGFloat)getCellHeightWithData:(RXMLExhibitorInformationModel*)model
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width-30;
    if([model.CompanyName_chn isEqualToString:@""]&&[model.CompanyName_eng isEqualToString:@""])
    {
        return 0;
    }
    //只有中文名
    else if([model.CompanyName_eng isEqualToString:@""])
    {
        return 36+[XXTool getTextHeightByText:model.CompanyName_chn Font:[XXTool systemFontOfSize:16.5] Width:width];
    }
    //只有英文名
    else if ([model.CompanyName_chn isEqualToString:@""])
    {
        return 36+[XXTool getTextHeightByText:model.CompanyName_eng Font:[XXTool systemFontOfSize:16.5] Width:width];
    }
    //都有
    else
    {
        
        return 36+[XXTool getTextHeightByText:model.CompanyName_chn Font:[XXTool systemFontOfSize:16.5] Width:width]+[XXTool getTextHeightByText:model.CompanyName_eng Font:[XXTool systemFontOfSize:16.5] Width:width];
       
    }
    
}


@end
